// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   TrdReviewScrPanel.java

package com.boci.clientapp.trading;

import com.boci.clientapp.main.ClientAppLoader;
import com.boci.clientapp.trading.action.ReviewAction;
import com.boci.clientapp.trading.vo.ReviewHKTradingVO;
import com.boci.clientapp.trading.vo.ReviewUSTradingVO;
import com.boci.common.constant.ClientAppConst;
import com.boci.common.ui.AbstractPanel;
import com.boci.common.util.*;
import com.boci.common.vo.ResponseVO;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.util.HashMap;
import java.util.Locale;
import javax.swing.*;

public class TrdReviewScrPanel extends AbstractPanel
{

    public void acceptDuplicate()
    {
        acceptDupFlag = true;
    }

    public void resetDuplicateFlag()
    {
        acceptDupFlag = false;
    }

    public TrdReviewScrPanel(Locale pLocale, String pModuleName, String pScreenName)
    {
        super(pLocale, pModuleName, pScreenName);
        msgConf = ClientAppLoader.getMessagesConfigurator();
        hkMktFlag = false;
        intHIndex = 10;
        intVIndex = 2;
        acceptDupFlag = false;
        initGUI();
        setText(pLocale);
    }

    public void setText(Locale pLocale)
    {
        super.setText(pLocale);
        setFont(pLocale);
        currentLocale = pLocale;
        if(hkMktFlag)
            refresh(currentHKVO);
        else
            refresh(currentUSVO);
        lblTrans.setText(msgConf.getUIMessages("TRADING.TRANSACTION", pLocale));
        lblOrdType.setText(msgConf.getUIMessages("TRADING.ORDER_TYPE", pLocale));
        lblCode.setText(msgConf.getUIMessages("TRADING.CODE", pLocale));
        lblName.setText(msgConf.getUIMessages("TRADING.NAME", pLocale));
        lblDuration.setText(msgConf.getUIMessages("TRADING.DURATION", pLocale));
        lblQty.setText(msgConf.getUIMessages("TRADING.QUANTITY", pLocale));
        lblPrice.setText(msgConf.getUIMessages("TRADING.PRICE", pLocale));
        lblQuestion.setText(msgConf.getUIMessages("TRADING.QUESTION", pLocale));
        btnSendOrder.setText(msgConf.getUIMessages("TRADING.SEND", pLocale));
        btnCancel.setText(msgConf.getUIMessages("TRADING.CANCEL", pLocale));
        btnBack.setText(msgConf.getUIMessages("TRADING.BACK", pLocale));
    }

    private void setFont(Locale pLocale)
    {
        lblTitle.setFont(ClientAppLoader.getLargeBoldTextFont(pLocale));
        lblTrans.setFont(ClientAppLoader.getLargeBoldTextFont(pLocale));
        lblOrdType.setFont(ClientAppLoader.getLargeBoldTextFont(pLocale));
        lblCode.setFont(ClientAppLoader.getLargeBoldTextFont(pLocale));
        lblName.setFont(ClientAppLoader.getLargeBoldTextFont(pLocale));
        lblDuration.setFont(ClientAppLoader.getLargeBoldTextFont(pLocale));
        lblQty.setFont(ClientAppLoader.getLargeBoldTextFont(pLocale));
        lblPrice.setFont(ClientAppLoader.getLargeBoldTextFont(pLocale));
        lblQuestion.setFont(ClientAppLoader.getLargeBoldTextFont(pLocale));
        btnSendOrder.setFont(ClientAppLoader.getBoldButtonFont(pLocale));
        btnCancel.setFont(ClientAppLoader.getPlainButtonFont(pLocale));
        btnBack.setFont(ClientAppLoader.getPlainButtonFont(pLocale));
        lblCodeResult.setFont(ClientAppLoader.getLargePlainTextFont(pLocale));
        lblQtyResult.setFont(ClientAppLoader.getLargePlainTextFont(pLocale));
        lblPriceResult.setFont(ClientAppLoader.getLargePlainTextFont(pLocale));
        taNameResult.setFont(ClientAppLoader.getLargePlainTextFont(pLocale));
        lblDurationResult.setFont(ClientAppLoader.getLargePlainTextFont(pLocale));
        lblOrdTypeResult.setFont(ClientAppLoader.getLargePlainTextFont(pLocale));
        lblTransResult.setFont(ClientAppLoader.getLargeBoldTextFont(pLocale));
    }

    private void initGUI()
    {
        lblTitle = new JLabel();
        lblTrans = new JLabel();
        lblOrdType = new JLabel();
        lblCode = new JLabel();
        lblName = new JLabel();
        lblDuration = new JLabel();
        lblQty = new JLabel();
        lblPrice = new JLabel();
        lblTransResult = new JLabel();
        lblCodeResult = new JLabel();
        taNameResult = new JTextArea();
        taNameResult.setOpaque(false);
        taNameResult.setEditable(false);
        taNameResult.setLineWrap(true);
        taNameResult.setWrapStyleWord(true);
        lblQtyResult = new JLabel();
        lblPriceResult = new JLabel();
        lblDurationResult = new JLabel();
        lblOrdTypeResult = new JLabel();
        btnSendOrder = new JButton();
        btnBack = new JButton();
        btnCancel = new JButton();
        lblQuestion = new JLabel();
        setLayout(null);
        setPreferredSize(new Dimension(710, 210));
        setBackground(Color.WHITE);
        add(lblTitle);
        lblTrans.setHorizontalAlignment(4);
        add(lblTrans);
        lblOrdType.setHorizontalAlignment(4);
        add(lblOrdType);
        lblCode.setHorizontalAlignment(4);
        add(lblCode);
        lblName.setHorizontalAlignment(4);
        add(lblName);
        lblDuration.setHorizontalAlignment(4);
        add(lblDuration);
        lblQty.setHorizontalAlignment(4);
        add(lblQty);
        lblPrice.setHorizontalAlignment(4);
        add(lblPrice);
        add(lblCodeResult);
        add(taNameResult);
        add(lblQtyResult);
        add(lblPriceResult);
        add(lblDurationResult);
        add(lblTransResult);
        add(lblOrdTypeResult);
        add(lblQuestion);
        add(btnSendOrder);
        add(btnBack);
        add(btnCancel);
        btnSendOrder.setMargin(new Insets(2, 2, 2, 2));
        lblTitle.setBounds(13, 1, 207, 20);
        lblTrans.setBounds(intHIndex + 0, 70 + intVIndex, 120, 20);
        lblOrdType.setBounds(intHIndex + 0, 130 + intVIndex, 120, 20);
        lblCode.setBounds(intHIndex + 0, 50 + intVIndex, 120, 20);
        lblName.setBounds(intHIndex + 0, 30 + intVIndex, 120, 20);
        lblDuration.setBounds(intHIndex + 0, 150 + intVIndex, 120, 20);
        lblQty.setBounds(intHIndex + 0, 90 + intVIndex, 120, 20);
        lblPrice.setBounds(intHIndex + 0, 110 + intVIndex, 120, 20);
        lblCodeResult.setBounds(intHIndex + 135, 50 + intVIndex, 150, 20);
        lblTransResult.setBounds(intHIndex + 135, 70 + intVIndex, 150, 20);
        taNameResult.setBounds(intHIndex + 135, 16 + intVIndex, 600, 35);
        lblQtyResult.setBounds(intHIndex + 135, 90 + intVIndex, 150, 20);
        lblPriceResult.setBounds(intHIndex + 135, 110 + intVIndex, 150, 20);
        lblDurationResult.setBounds(intHIndex + 135, 150 + intVIndex, 300, 20);
        lblOrdTypeResult.setBounds(intHIndex + 135, 130 + intVIndex, 300, 20);
        lblQuestion.setBounds(305, 85, 500, 20);
        btnSendOrder.setBounds(intHIndex + 437, 110, 120, 25);
        btnCancel.setBounds(intHIndex + 574, 110, 120, 25);
        btnBack.setBounds(intHIndex + 300, 110, 120, 25);
        btnSendOrder.setActionCommand("SEND ORDER");
        btnSendOrder.addActionListener(this);
        btnCancel.setActionCommand("CANCEL");
        btnCancel.addActionListener(this);
        btnBack.setActionCommand("BACK");
        btnBack.addActionListener(this);
    }

    public void actionPerformed(ActionEvent e)
    {
        String strActionType = e.getActionCommand();
        if(validate(strActionType))
        {
            PerformanceLogger.startAppTimer();
            ReviewAction reviewAction = new ReviewAction();
            reviewAction.doProcess(getInputValue(strActionType), strActionType);
            PerformanceLogger.stopAppTimer();
            PerformanceLogger.doLog((new StringBuilder()).append(getScreenName()).append(".").append(strActionType).toString());
        }
    }

    public void refresh()
    {
        setDefFocus();
    }

    public void refresh(ResponseVO pResponseVO)
    {
        if(pResponseVO == null)
        {
            lblCodeResult.setText("");
            taNameResult.setText("");
            lblQtyResult.setText("");
            lblPriceResult.setText("");
            lblDurationResult.setText("");
            lblOrdTypeResult.setText("");
            lblTransResult.setText("");
            return;
        }
        if(pResponseVO instanceof ReviewHKTradingVO)
        {
            currentHKVO = (ReviewHKTradingVO)pResponseVO;
            hkMktFlag = true;
            lblTitle.setText(msgConf.getUIMessages("TRADING.HK_MARKET", currentLocale));
            lblCodeResult.setText(currentHKVO.getSymbol());
            String strName;
            if(currentLocale.equals(ClientAppConst.ZH_CN) && currentHKVO.getName_CHS() != null && currentHKVO.getName_CHS().length() != 0)
                strName = currentHKVO.getName_CHS();
            else
            if(currentLocale.equals(ClientAppConst.ZH_HK) && currentHKVO.getName_CHI() != null && currentHKVO.getName_CHI().length() != 0)
            {
                strName = currentHKVO.getName_CHI();
            } else
            {
                strName = currentHKVO.getName();
                taNameResult.setFont(ClientAppLoader.getLargePlainTextFont(ClientAppConst.EN_US));
            }
            FontMetrics fm = taNameResult.getFontMetrics(taNameResult.getFont());
            if(fm.stringWidth(strName) > 590)
            {
                if(currentLocale.equals(ClientAppConst.EN_US))
                {
                    taNameResult.setBounds(intHIndex + 135, 15 + intVIndex, 590, 40);
                    taNameResult.setWrapStyleWord(true);
                } else
                {
                    taNameResult.setBounds(intHIndex + 135, 13 + intVIndex, 590, 40);
                    taNameResult.setWrapStyleWord(false);
                }
            } else
            {
                taNameResult.setBounds(intHIndex + 135, 32 + intVIndex, 590, 20);
            }
            taNameResult.setText(strName);
            String strQty = StringUtil.formatQtyValue(currentHKVO.getQuantity());
            lblQtyResult.setText(strQty);
            String strCCY = msgConf.getUIMessages("HKD", currentLocale);
            String strPrice = StringUtil.formatPriceValue(currentHKVO.getPrice(), strCCY);
            lblDurationResult.setText(msgConf.getUIMessages("DAY", currentLocale));
            String strOrderType = currentHKVO.getOrderType();
            lblOrdTypeResult.setText(msgConf.getUIMessages(strOrderType, currentLocale));
            String strNoPriceTypes[] = ClientAppLoader.getNoPriceOrdTypes();
            boolean isNoPriceType = false;
            int i = 0;
            do
            {
                if(i >= strNoPriceTypes.length)
                    break;
                if(strNoPriceTypes[i].equals(strOrderType))
                {
                    isNoPriceType = true;
                    break;
                }
                i++;
            } while(true);
            if(isNoPriceType)
                lblPriceResult.setText("");
            else
                lblPriceResult.setText(strPrice);
            String strTransaction = currentHKVO.getBuyOrSell();
            lblTransResult.setText(msgConf.getUIMessages(strTransaction, currentLocale));
            if(currentHKVO.getBuyOrSell().equals("BUY"))
            {
                setBackground(ClientAppConst.buyBackground);
                lblTransResult.setForeground(ClientAppConst.buyFontColor);
            } else
            {
                setBackground(ClientAppConst.sellBackground);
                lblTransResult.setForeground(ClientAppConst.sellFontColor);
            }
        } else
        if(pResponseVO instanceof ReviewUSTradingVO)
        {
            currentUSVO = (ReviewUSTradingVO)pResponseVO;
            hkMktFlag = false;
            lblTitle.setText(msgConf.getUIMessages("TRADING.US_MARKET", currentLocale));
            lblCodeResult.setText(currentUSVO.getSymbol());
            String strName;
            if(currentLocale.equals(ClientAppConst.ZH_CN) && currentUSVO.getName_CHS() != null && currentUSVO.getName_CHS().length() != 0)
                strName = currentUSVO.getName_CHS();
            else
            if(currentLocale.equals(ClientAppConst.ZH_HK) && currentUSVO.getName_CHI() != null && currentUSVO.getName_CHI().length() != 0)
            {
                strName = currentUSVO.getName_CHI();
            } else
            {
                strName = currentUSVO.getName();
                taNameResult.setFont(ClientAppLoader.getLargePlainTextFont(ClientAppConst.EN_US));
            }
            FontMetrics fm = taNameResult.getFontMetrics(taNameResult.getFont());
            if(fm.stringWidth(strName) > 590)
            {
                if(currentLocale.equals(ClientAppConst.EN_US))
                {
                    taNameResult.setBounds(intHIndex + 135, 15 + intVIndex, 590, 40);
                    taNameResult.setWrapStyleWord(true);
                } else
                {
                    taNameResult.setBounds(intHIndex + 135, 13 + intVIndex, 590, 40);
                    taNameResult.setWrapStyleWord(false);
                }
            } else
            {
                taNameResult.setBounds(intHIndex + 135, 32 + intVIndex, 590, 20);
            }
            taNameResult.setText(strName);
            String strQty = StringUtil.formatQtyValue(currentUSVO.getQuantity());
            lblQtyResult.setText(strQty);
            String strCCY = msgConf.getUIMessages("USD", currentLocale);
            String strPrice = StringUtil.formatPriceValue(currentUSVO.getPrice(), strCCY);
            lblDurationResult.setText(msgConf.getUIMessages("DAY", currentLocale));
            String strOrderType = currentUSVO.getOrderType();
            lblOrdTypeResult.setText(msgConf.getUIMessages(strOrderType, currentLocale));
            String strNoPriceTypes[] = ClientAppLoader.getNoPriceOrdTypes();
            boolean isNoPriceType = false;
            int i = 0;
            do
            {
                if(i >= strNoPriceTypes.length)
                    break;
                if(strNoPriceTypes[i].equals(strOrderType))
                {
                    isNoPriceType = true;
                    break;
                }
                i++;
            } while(true);
            if(isNoPriceType)
                lblPriceResult.setText("");
            else
                lblPriceResult.setText(strPrice);
            String strTransaction = currentUSVO.getBuyOrSell();
            lblTransResult.setText(msgConf.getUIMessages(strTransaction, currentLocale));
            if(currentUSVO.getBuyOrSell().equals("BUY"))
            {
                setBackground(ClientAppConst.buyBackground);
                lblTransResult.setForeground(ClientAppConst.buyFontColor);
            } else
            {
                setBackground(ClientAppConst.sellBackground);
                lblTransResult.setForeground(ClientAppConst.sellFontColor);
            }
        }
        setDefFocus();
    }

    public HashMap getInputValue(String pActionType)
    {
        if(hkMktFlag && currentHKVO == null)
            return null;
        if(!hkMktFlag && currentUSVO == null)
            return null;
        HashMap inpMap = new HashMap();
        if(hkMktFlag)
        {
            inpMap.put("name", currentHKVO.getName());
            inpMap.put("symbol", currentHKVO.getSymbol());
            inpMap.put("qty", currentHKVO.getQuantity());
            inpMap.put("price", currentHKVO.getPrice());
            inpMap.put("buyorsell", currentHKVO.getBuyOrSell());
            inpMap.put("orderType", currentHKVO.getOrderType());
            inpMap.put("orderQualifier", currentHKVO.getOrderQualifier());
        } else
        {
            inpMap.put("symbol", currentUSVO.getSymbol());
            inpMap.put("qty", currentUSVO.getQuantity());
            inpMap.put("price", currentUSVO.getPrice());
            inpMap.put("buyorsell", currentUSVO.getBuyOrSell());
            inpMap.put("ordtype", currentUSVO.getOrderType());
        }
        if(acceptDupFlag)
            inpMap.put("acceptDuplicate", "true");
        return inpMap;
    }

    public boolean validate(String pActionType)
    {
        return true;
    }

    public void setDefFocus()
    {
        SwingUtilities.invokeLater(new Runnable() {

            public void run()
            {
                btnBack.requestFocus();
            }
        }
);
    }

    private JLabel lblQuestion;
    private JLabel lblTitle;
    private JLabel lblTrans;
    private JLabel lblOrdType;
    private JLabel lblCode;
    private JLabel lblName;
    private JLabel lblDuration;
    private JLabel lblQty;
    private JLabel lblPrice;
    private JTextArea taNameResult;
    private JLabel lblTransResult;
    private JLabel lblCodeResult;
    private JLabel lblQtyResult;
    private JLabel lblPriceResult;
    private JLabel lblDurationResult;
    private JLabel lblOrdTypeResult;
    private JButton btnSendOrder;
    private JButton btnBack;
    private JButton btnCancel;
    private Locale currentLocale;
    private MessagesConfigurator msgConf;
    private ReviewHKTradingVO currentHKVO;
    private ReviewUSTradingVO currentUSVO;
    private boolean hkMktFlag;
    private int intHIndex;
    private int intVIndex;
    private boolean acceptDupFlag;

}
